home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
programr
/
ole2book.zip
/
CHAP10.ZIP
/
CHAP10
/
SCHMOO
/
FIGURE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-13
|
7KB
|
320 lines
/*
* FIGURE.CPP
* Schmoo Figure Object Chapter 10
*
* Implementation of the CFigure object for Schmoo.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "schmoo.h"
/*
* CFigure::CFigure
* CFigure::~CFigure
*
* Parameters (Constructor):
* pfnDestroy LPFNDESTROYED to call when an object is destroyed.
* pDoc LPCSchmooDoc we're associated with.
*/
CFigure::CFigure(LPFNDESTROYED pfnDestroy, LPCSchmooDoc pDoc)
{
m_cRef=0;
m_pfnDestroy=pfnDestroy;
m_pFR=NULL; //We get this later through FrameSet.
m_pDoc=pDoc;
m_pPL=pDoc->m_pPL;
m_fEmbedded=FALSE;
//NULL any contained interfaces initially.
m_pIPersistStorage=NULL;
m_pIDataObject=NULL;
m_pIDataAdviseHolder=NULL;
m_pIOleObject=NULL;
m_pIOleAdviseHolder=NULL;
m_pIOleClientSite=NULL;
m_cf=pDoc->m_cf;
//These are for IDataObject::QueryGetData
m_cfeGet=CFORMATETCGET;
SETDefFormatEtc(m_rgfeGet[0], pDoc->m_cf, TYMED_HGLOBAL);
SETDefFormatEtc(m_rgfeGet[1], pDoc->m_cfEmbedSource, TYMED_ISTORAGE);
SETDefFormatEtc(m_rgfeGet[2], pDoc->m_cfObjectDescriptor, TYMED_HGLOBAL);
SETDefFormatEtc(m_rgfeGet[3], CF_METAFILEPICT, TYMED_MFPICT);
SETDefFormatEtc(m_rgfeGet[4], CF_BITMAP, TYMED_GDI);
return;
}
CFigure::~CFigure(void)
{
//Free contained interfaces.
if (NULL!=m_pIOleObject)
delete m_pIOleObject;
if (NULL!=m_pIDataObject)
delete m_pIDataObject;
if (NULL!=m_pIPersistStorage)
delete m_pIPersistStorage;
return;
}
/*
* CFigure::QueryInterface
* CFigure::AddRef
* CFigure::Release
*
* Purpose:
* IUnknown members for CFigure object.
*/
STDMETHODIMP CFigure::QueryInterface(REFIID riid, LPVOID FAR *ppv)
{
*ppv=NULL;
if (IsEqualIID(riid, IID_IUnknown))
*ppv=(LPVOID)this;
if (IsEqualIID(riid, IID_IPersist) || IsEqualIID(riid, IID_IPersistStorage))
*ppv=(LPVOID)m_pIPersistStorage;
if (IsEqualIID(riid, IID_IDataObject))
*ppv=(LPVOID)m_pIDataObject;
if (IsEqualIID(riid, IID_IOleObject))
*ppv=(LPVOID)m_pIOleObject;
//AddRef any interface we'll return.
if (NULL!=*ppv)
{
((LPUNKNOWN)*ppv)->AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP_(ULONG) CFigure::AddRef(void)
{
return ++m_cRef;
}
STDMETHODIMP_(ULONG) CFigure::Release(void)
{
ULONG cRefT;
cRefT=--m_cRef;
if (0==m_cRef)
{
/*
* Tell the housing that an object is going away so it can
* shut down if appropriate.
*/
if (NULL!=m_pfnDestroy)
(*m_pfnDestroy)();
delete this;
}
return cRefT;
}
/*
* CFigure::FInit
*
* Purpose:
* Performs any intiailization of a CFigure that's prone to failure
* that we also use internally before exposing the object outside.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if the function is successful, FALSE otherwise.
*/
BOOL CFigure::FInit(void)
{
//Allocate contained interfaces.
m_pIPersistStorage=new CImpIPersistStorage(this, (LPUNKNOWN)this);
if (NULL==m_pIPersistStorage)
return FALSE;
m_pIDataObject=new CImpIDataObject(this, (LPUNKNOWN)this);
if (NULL==m_pIDataObject)
return FALSE;
m_pIOleObject=new CImpIOleObject(this, (LPUNKNOWN)this);
if (NULL==m_pIOleObject)
return FALSE;
return TRUE;
}
/*
* CFigure::FrameSet
*
* Purpose:
* Provides the compound document object with access to the frame
* of this application for UI purposes.
*
* Parameters:
* pFR LPCSchmooFrame of the frame window.
*
* Return Value:
* None
*/
void CFigure::FrameSet(LPCSchmooFrame pFR)
{
m_pFR=pFR;
return;
}
/*
* CFigure::FIsDirty
*
* Purpose:
* Checks if the document is dirty. This can be called from
* IPersistStorage::IsDirty which doesn't have access to CSchmooDoc.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if dirty, FALSE if clean.
*/
BOOL CFigure::FIsDirty(void)
{
return m_pDoc->m_fDirty;
}
/*
* CFigure::FIsEmbedded
*
* Purpose:
* Answers if the object is embedded or not.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if the object is embedded, FALSE otherwise.
*/
BOOL CFigure::FIsEmbedded(void)
{
return m_fEmbedded;
}
/*
* CFigure::SendAdvise
*
* Purpose:
* Calls the appropriate IOleClientSite or IAdviseSink member function
* for various events such as closure, renaming, saving, etc.
*
* Parameters:
* uCode UINT OBJECTCODE_* identifying the notification.
*
* Return Value:
* None
*/
void CFigure::SendAdvise(UINT uCode)
{
switch (uCode)
{
case OBJECTCODE_SAVED:
if (NULL!=m_pIOleAdviseHolder)
m_pIOleAdviseHolder->SendOnSave();
break;
case OBJECTCODE_CLOSED:
if (NULL!=m_pIOleAdviseHolder)
m_pIOleAdviseHolder->SendOnClose();
break;
case OBJECTCODE_RENAMED:
//Call IOleAdviseHolder::SendOnRename (later)
break;
case OBJECTCODE_SAVEOBJECT:
if (m_pDoc->m_fDirty && NULL!=m_pIOleClientSite)
m_pIOleClientSite->SaveObject();
break;
case OBJECTCODE_DATACHANGED:
//No flags are necessary here.
if (NULL!=m_pIDataAdviseHolder)
m_pIDataAdviseHolder->SendOnDataChange(m_pIDataObject, 0, 0);
break;
case OBJECTCODE_SHOWWINDOW:
if (NULL!=m_pIOleClientSite)
m_pIOleClientSite->OnShowWindow(TRUE);
break;
case OBJECTCODE_HIDEWINDOW:
if (NULL!=m_pIOleClientSite)
m_pIOleClientSite->OnShowWindow(FALSE);
break;
case OBJECTCODE_SHOWOBJECT:
if (NULL!=m_pIOleClientSite)
m_pIOleClientSite->ShowObject();
break;
}
return;
}